package OrdersSystem;

import DBSystem.*;

import java.util.ArrayList;

/**
 * 
 * This class is responsible for the gathering of User's history and tracking a specific order.
 * 
 * @author iSolutions-Team Orders
 *
 */
public class HistoryTracking {
	/**
	 * Contains orders, which have been demanded to be retrieved from the database.  
	 */
    private ArrayList<Order> orderHistory;
  
	/**
	 * Constructor of the class, which gets all the orders, which were made in the system.
	 * 
	 */ 
    public HistoryTracking() {
    	orderHistory = retrieveHistoryOfAllOrders();
    }
    
	/**
	 * Constructor of the class, which gets the customerID in order to retrieve the history of their orders.
	 * @param customerID the number, which uniquely identifies a customer.
	 */   
    public HistoryTracking(int customerID) {
    	orderHistory = retrieveHistory(customerID);
    }	
    
	//Methods
	/**
	 * Gets an attribute.
	 * @return orderHistory
	*/
	public ArrayList<Order> getOrderHistory() {
		return orderHistory;
	}
    
	/**
	 * A method used to retrieve the history of a particular customerID.
	 * @param customerID the number, which uniquely identifies a customer.
	 */ 
	private ArrayList<Order> retrieveHistory(int customerID) {  // returns the Orders that have this userID
		DBSystemComm dbCommunicator = new DBSystemComm(); // connect to the database
		return dbCommunicator.getOrders(customerID);
	}

	/**
	 * A method used to retrieve all the orders stored in the database.
	 * 
	 */
	private ArrayList<Order> retrieveHistoryOfAllOrders() {  // returns the Orders that have this userID
		DBSystemComm dbCommunicator = new DBSystemComm(); // connect to the database
		return dbCommunicator.getAllOrders();
	}
	
}
